<!DOCTYPE html>
<html lang="en">

<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <link href="./css/lottery.css" rel="stylesheet">
  <!-- <script type="text/javascript" src="./lib/js/evm.js"></script>
    <script type="text/javascript" src="./lib/js/Evm_djyw.js"></script>
    <script type="text/javascript" src="./lib/js/key.js"></script>
    <script type="text/javascript" src="js/jquery.min.js?v="+(new Date()).getSeconds()></script>
    <script src="./lib/js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script> -->
  <!-- <script src="./js/public.js" type="text/javascript" charset="utf-8"></script> -->
  <script src="./js/getId.js" type="text/javascript" charset="utf-8"></script>
  <title>抽奖</title>
</head>

<body>
  <div id="content">
    <table id="cj-box">
      <tr>
        <td>
          <div id="prize1" class="prize"></div>
        </td>
        <td>
          <div id="prize2" class="prize"></div>
        </td>
        <td>
          <div id="prize3" class="prize"></div>
        </td>
        <td>
          <div id="prize4" class="prize"></div>
        </td>
      </tr>
      <tr>
        <td>
          <div id="prize10" class="prize"></div>
        </td>
        <td colspan="2" class="choujiang" id="choujiang">
          <div id="lottery" class="lottery active"></div>
        </td>
        <td>
          <div id="prize5" class="prize"></div>
        </td>
      </tr>
      <tr>
        <td>
          <div id="prize9" class="prize"></div>
        </td>
        <td>
          <div id="prize8" class="prize"></div>
        </td>
        <td>
          <div id="prize7" class="prize"></div>
        </td>
        <td>
          <div id="prize6" class="prize"></div>
        </td>
      </tr>
    </table>
  </div>

  <div class="turntablelist" id="turntablelist" style="display:none;">
    <img src="./images/lottery/jplogo.png" alt="">
  </div>

  <div id="back">
    <div class="back" id="backbtn">
    </div>
  </div>
  <div class="title-1"></div>
  <div class="title-2"></div>

  <div style="display:none;position: absolute;top:52px;right:33px;"><img src="./images/bg-guanggao.png" alt=""></div>
</body>
<script>
  //根据传入的id，设置对应的图片
  var currentId = getCookie('base_id');
  console.log(currentId)
  document.getElementById('content').style.backgroundImage = 'url("./public/upload/admin/yjjd/' + currentId +
    '/lottery.png")'
</script>
<script>
//   这个页面逻辑是这样，
// 一进来就判断“是否满足3次抽奖条件”
// 如果sts == 1
// 可以继续点击抽奖按钮
// 如果sts == 0或者sts == 2
// 提示信息，然后就2秒后执行跳转指定地址。
// 现要求，按返回键可以返回根据后台传的地址到指定页面，按退出按钮，可以返回指定根据后台传的地址到指定页面
// 如果是portal，则跳到固定页。如果url为空，则返回上一页。如果url不是“portal”，则跳到url的页面
var urladdress;
  function getReturnUrl(url, sts) {
    var ajax;
    if (window.XMLHttpRequest) {
      ajax = new XMLHttpRequest();
    } else {
      ajax = new ActiveXObject('Microsoft.XMLHTTP');
    }
    //判断是否满足3次抽奖条件
    ajax.open('post', STATICURL + "activity/getbackurl", true);
    ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajax.send('base_id=' + getCookie('base_id'));
    ajax.onreadystatechange = function () {
      if (ajax.readyState == 4 && ajax.status == 200) {
        // debugger
        console.log(url, '--------')
        var text = ajax.responseText;
        // if (text.length != 0) {
        //   var response = eval("(" + text + ")");
        //   // url = response
        // }
        console.log(text);
        url = text;
        urladdress=text;
        // EVM.cookie.setValue('urladdress',url)
        if (sts == 0) {
          prompt("今日参与次数已满，明天再来");
          gobackurl(url)

        } else if (sts == 2) {
          prompt('您本次活动已中奖，请下次参与');
          gobackurl(url)
        } else if (sts == 1) {
          console.log('可以继续抽奖')
          // forceBackUrl = window.location.href
          // document.getElementById('promt').innerHTML = forceBackUrl + '1234'
          // alert(forceBackUrl)
        }
      }
    }
  }
  // 约定：如果url是“portal”，则跳到固定页。如果url为空，则返回上一页。如果url不是“portal”，则跳到url的页面
  function gobackurl(url) {
    if ((url.toLowerCase()) == "portal") {
      setTimeout(function () {
        if (typeof (Android) != "undefined") { // 安卓盒子
          iPanel.eventFrame.openPortal();
        } else {
          window.location.href = "http://10.65.255.6:8080/portalrouting/pr.do?stbid=" + hardware.STB.serialNumber;
        }
      }, 2000)

    } else if (url == "" || url == null) {
      setTimeout(function () {
        history.go(-1);
      }, 2000)

    } else {
      setTimeout(function () {
        window.location.href = url
      }, 2000)
    }
  }
</script>
<script>
  var returnURL = './index.html'
  window.onload = function () {
    var ajax;
    if (window.XMLHttpRequest) {
      ajax = new XMLHttpRequest();
    } else {
      ajax = new ActiveXObject('Microsoft.XMLHTTP');
    }
    //判断是否满足3次抽奖条件
    ajax.open('post', STATICURL + "activity/getRecord", true);
    ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajax.send('tv_no=' + tv_no + '&tv_card=' + tv_card + '&base_id=' + getCookie('base_id') + '&isalone=' + isalone);
    ajax.onreadystatechange = function () {
      if (ajax.readyState == 4 && ajax.status == 200) {
        var text = ajax.responseText;
        if (text.length != 0) {
          var response = eval("(" + text + ")");
          //alert('gansita');
          // math = response.prize_site + 1;
          // name = response.prize_name;
          // prize_id = response.prize_id;
          // type = response.type;
          getReturnUrl(returnURL, response.sts);
          // alert(response.sts);

        }
      }
    }
  }
</script>

<script type="text/javascript" src="js/tool.js?v=" +(new Date()).getSeconds()></script>

<script type="text/javascript" src="js/common.js?v=" +(new Date()).getSeconds()></script>

<script type="text/javascript" src="js/address1.js?v=" +(new Date()).getSeconds()></script>

<script type="text/javascript" src="js/lottery.js?v=" +(new Date()).getSeconds()+ 10086></script>

</html>